package com.paranoidvulture.javaEngine.MapLayers;

import java.awt.Graphics2D;
import java.awt.Image;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;

import javax.imageio.ImageIO;

import com.paranoidvulture.javaEngine.Utilities.Camera2D;


public class Terrain {
	private int tileWidth = 64;
	private int tileHeight = 64;
	//private String rootFolder ="TestGame/Source/";
	private List<Image> tileTypes;
	
	public Terrain(String[] tileNames){
		this.tileTypes = new LinkedList<Image>();
		try{
			for (int i = 0; i< tileNames.length; i++){
				 //ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
				 InputStream input = ClassLoader.getSystemResourceAsStream(tileNames[i]);
				 Image temp = ImageIO.read(input);
				 this.tileTypes.add(temp);
			}
		}catch(Exception ex){}
	}
	
	public int getTileWidth(){
		return tileWidth;
	}
	
	public void setTileWidth(int tileWidth){
		this.tileWidth = tileWidth;
	}
	
	public int getTileHeight(){
		return tileHeight;
	}
	
	public void setTileHeight(int tileHeight){
		this.tileHeight = tileHeight;
	}
	
	
	//test tiles
	public int[][] newTerrain ={
			{0,1,1,2,2,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,1,1,2,2,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,1,1,2,2,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
        };
	
	public int[][] getMap(){
		return newTerrain;
	}
	
	public void addTiles(Image tile){
		this.tileTypes.add(tile);
	}
	

	
	public void draw(Graphics2D g, Camera2D cam){
		for (int y = 0; y < newTerrain.length; y++){
			for (int x = 0; x < newTerrain[0].length; x++){
				g.drawImage(this.tileTypes.get(newTerrain[y][x]), (int)(x*tileWidth - cam.getPosX()),
					(int)(y* tileHeight - cam.getPosY()), tileWidth, tileHeight, null);
			}
		}
	}
}
